package com.yesway.arc_menu;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AbsListView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import com.yesway.arc_menu.view.ArcMenu;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private ListView mListView;
    private ArcMenu arcMenu;
    private ArrayList<String> mDatas;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initDatas();
        initEvent();
        mListView.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,mDatas));
    }

    private void initEvent() {

        mListView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {

            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
                if(arcMenu.isOpen()){
                    arcMenu.toggleMenu(300);
                }
            }
        });
        arcMenu.setmMenuItemClickListener(new ArcMenu.OnMenuItemClickListener() {
            @Override
            public void onItemClick(View view, int index) {
                Toast.makeText(MainActivity.this,index+":"+view.getTag(),Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void initDatas() {
        mDatas = new ArrayList<>();

        for(int i = 'A';i<='Z';i++){
            mDatas.add((char)i+"");
        }

    }

    private void initView() {
        mListView = findViewById(R.id.id_list);
        arcMenu = findViewById(R.id.id_arcmenu);
    }
}
